package com.biz.primus.ms.product.service;

import com.biz.primus.commodity.enums.ProductRecommend;
import com.biz.primus.commodity.vo.frontend.ProductRecItemsVo;
import com.biz.primus.ms.base.service.AbstractBaseService;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品推荐Service实现
 *
 * @author 江南
 * @date 2017/1/20
 * @reviewer
 */
@Slf4j
@Service
public class ProductRecommendService extends AbstractBaseService {

    @Autowired
    private AliProductRecServiceHelper aliProductRecServiceHelper;

    private List<String> parseRecIds(List<List<String>> rec) {
        List<String> centerIds = Lists.newArrayList();
        for (List<String> stringList : rec) {
            centerIds.add(stringList.get(0));
        }
        return centerIds;
    }

    public ProductRecItemsVo recommend(ProductRecommend productRecommend, String productCode, String memberId) {
//        log.debug("recommend reqVo: {} {} {}",productRecommend,productCode,memberId);
//        if (productRecommend==null){
//            return null;
//        }
//        if (memberId == null){
//            memberId = "";
//        }
//        if(productCode == null){
//            productCode = "";
//        }
//        AliRecByUserProductReqVo reqVo;
//        if (productRecommend == ProductRecommend.DETAIL_PAGE){
//            reqVo = new AliRecByUserProductReqVo(RecConfig.AccessKeyID,RecConfig.AccessKeySecret,
//                    RecConfig.biz_code.kuaihe.name(),RecConfig.scn_code.detail.name(),memberId,productCode);
//        }else if (productRecommend == ProductRecommend.HOME_PAGE){
//            reqVo = new AliRecByUserProductReqVo(RecConfig.AccessKeyID,RecConfig.AccessKeySecret,
//                    RecConfig.biz_code.kuaihe.name(),RecConfig.scn_code.home.name(),memberId,productCode);
//        }else {
//            log.warn("未定义的推荐场景");
//            return null;
//        }
//        AliRecRespVo recommendByAli = aliProductRecServiceHelper.findRecommendByAli(reqVo);
//        return new ProductRecItemsVo(recommendByAli.getData().getTrace_id(), this.parseRecIds(recommendByAli.getData().getRec()));
        // TODO: 2017/11/23 test
        ProductRecItemsVo respVo = new ProductRecItemsVo();
        respVo.setTraceId("123132123");
        ArrayList<String> productCodes = Lists.newArrayList();
        productCodes.add("1");
        productCodes.add("2");
        respVo.setProductCodes(productCodes);
        return respVo;
    }
}
